#include "sys.h"
																				//	u	 f   .
unsigned char code smg[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xc1,0x8e,0x7f};
u8 NixieBuff[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
u8 smg1,smg2,smg3,smg4,smg5,smg6,smg7,smg8;



void nixieScan()
{
	static u8 index;
 	P0 = 0xff;
	hc138(7);
	hc138(0);

	P0 = 0x01 << index;
	hc138(6);
	hc138(0);


	P0 = NixieBuff[index];
	hc138(7);
	hc138(0);
	P0 = 0xff;

	index++;
	index &= 0x07;
}


void showMode0()
{
 	smg1 = 	11;
	smg2 = smg3 = smg4 = smg5 = 10;
	smg6 = U_val/100;
	smg7 = U_val%100/10;
	smg8 = U_val%10;
}					

void showMode1()
{	

    smg1 = 12;
	smg2 = smg3  = 10;
	smg4 = P_val/10000;
	smg5 = P_val%10000/1000;
	smg6 = P_val%1000/100;
	smg7 = P_val%100/10;
	smg8 = P_val%10;
	if(smg4 == 0)
	{
	 	smg4 = 10;
		if(smg5 == 0)
		{
		 	smg5 = 10;
			if(smg6 == 0)
			{
			 	smg6 = 10;		
			}
		}
	}
		
}

void show()
{
	if(nixieMode)
	{
		if(showMode)
			showMode1();
		else
			showMode0();
	}else{
	 	smg1 = smg2 = smg3 = smg4 = smg5 = smg6 = smg7 = smg8 = 10;
	}
     NixieBuff[0] = smg[smg1];
	 NixieBuff[1] = smg[smg2];
	 NixieBuff[2] = smg[smg3];
	 NixieBuff[3] = smg[smg4];
	 NixieBuff[4] = smg[smg5];
	 if(showMode)
		 NixieBuff[5] = smg[smg6];
	 else
		 NixieBuff[5] = smg[smg6]&0x7f;
	 NixieBuff[6] = smg[smg7];			 
	 NixieBuff[7] = smg[smg8];
}